<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>实现input表单和object对象的一个属性的双向数据绑定</title>
  <style type="text/css">
  * {
    padding: 0;
    margin: 0;
  }
  </style>
</head>
<body>
  <div id="box" class="box">
    <input type="text">
  </div>
<script src="https://cdn.staticfile.org/jquery/3.2.0/jquery.js"></script>
<script type="text/javascript">
 var obj = Object.defineProperty({}, 'a', {
    set: function(val) {
      $('input').val(val)
      console.log(obj.a, this === obj)
    },
    get: function() {
      return $("input").val().trim()
    }
 })

 $("input").on("input", function() {
    obj.a = this.value
 })

</script>
</body>
</html>